﻿package org.kolonitsky.alexey.flashui
{
  import flash.display.MovieClip;
  import flash.events.Event;
  import flash.events.MouseEvent;

  public class BtnPlay extends MovieClip
  {

    private var playIcon: MovieClip

    /** Constructor **/
    public function BtnPlay() {
      super();
      stop()
	  useHandCursor = true
	  buttonMode = true
      addEventListener(Event.ADDED_TO_STAGE, init)
      addEventListener(MouseEvent.ROLL_OUT, onRollOut)
      addEventListener(MouseEvent.ROLL_OVER, onRollOver)
      addEventListener(MouseEvent.MOUSE_UP, onClick)
    }


    public function init (event:Event): void {
      playIcon = MovieClip(getChildByName("playIconMc"))
      playIcon.gotoAndStop(1)
    }
    
    public function onRollOut (event:MouseEvent): void {
      gotoAndStop("up")
    }
    
    public function onRollOver (event:MouseEvent): void {
      gotoAndStop("over")
    }
    
    public function onClick (event:MouseEvent): void {
      gotoAndStop("over")
      selected = !selected
    }


    /**
     * @property selected
     * if selected is play
     * if not selected is stop 
     * @default not selected
     */
    private var _selected: Boolean = false

    public function get selected (): Boolean {
      return _selected
    }

    public function set selected (value:Boolean): void {
      _selected = value
      playIcon.gotoAndStop(value ? 2 : 1)
    }

  }
}